﻿Imports Microsoft.Win32.SafeHandles
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.ComponentModel

Public Class Mainframe

    Private Sub TestConnection()
        'FILECONFIG.ServerAddress = Trim(TxtServerAddress.Text)
        'FILECONFIG.Port = Trim(CInt(txtPort.Text))
        'FILECONFIG.Database = Trim(TxtDatabase.Text)
        'FILECONFIG.Username = Trim(txtUsername.Text)
        'FILECONFIG.Password = txtPassword.Text

        'Call conn2dbsettings()
    End Sub

    Private Sub Mainframe_Load(sender As Object, e As EventArgs) Handles Me.Load
        Call OnFormLoad()
    End Sub

    Private Sub BtnTutup_Click(sender As Object, e As EventArgs) Handles BtnTutup.Click
        Me.Close()
    End Sub

    Private Sub BtnTes_Click(sender As Object, e As EventArgs) Handles BtnTes.Click
        'Masukkan nilai pada kontrol ke dalam variabel
        Call PUSH_Parameter()
        'Jalankan test
        Call LoadTest()
    End Sub

    Private Sub TxtPassword_TextChanged(sender As Object, e As EventArgs) Handles TxtPassword.TextChanged

    End Sub

    Private Sub BtnSimpan_Click(sender As Object, e As EventArgs) Handles BtnSimpan.Click
        'Lakukan re-test untuk memastikan settingnya benar-benar valid
        Call PUSH_Parameter()
        Call LoadTest()

        'If IsRunAsAdmin() = True Then
        '    MsgBox("Admin")
        'Else
        '    MsgBox("Not Admin")
        'End If

        'Lanjutkan ke langkah selanjutnya jika tidak terdapat error
        If CHECK_FOR_ERROR(ISCONTAINERRORS) = False Then
            Call PUSH_Config_to_Database(FILECONFIG.ServerAddress, FILECONFIG.Port, FILECONFIG.Username, FILECONFIG.Password, FILECONFIG.Database)
        End If
    End Sub

    Private Function CHECK_FOR_ERROR(ByVal ErrorValue As Boolean) As Boolean
        If ErrorValue = True Then
            MessageBox.Show("Tidak dapat menyimpan pengaturan." & vbCrLf & "Silahkan periksa kembali pengaturan anda.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return True
        Else
            Return False
        End If
    End Function
End Class
